package com.zking.ssm.NH.controller;



import com.zking.ssm.NH.model.ThotelFacility;

import com.zking.ssm.NH.service.IThotelFacilityService;
import com.zking.ssm.util.JsonData;
import com.zking.ssm.util.PageBean;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/lxl")
public class ThotelFacilityController {
    @Autowired
    private IThotelFacilityService thotelFacilityService;

    private ThotelFacility thotelFacility;


    @ModelAttribute
    public void init(Model model){
        ThotelFacility thotelFacility=new ThotelFacility();
        model.addAttribute("thotelFacility",thotelFacility);
    }

    @RequestMapping(value = "/lista")
    @ResponseBody
    public JsonData lista(ThotelFacility thotelFacility, PageBean pageBean) {
        List<ThotelFacility> bookList = thotelFacilityService.lista(thotelFacility, pageBean);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("查询成功");
        jsonData.setResult(bookList);
        return jsonData;
    }


    @RequestMapping(value = "/insert")
    @ResponseBody
    public JsonData insert(ThotelFacility thotelFacility) {
//        long l = System.currentTimeMillis();
//        thotelFacility.setCreateTime(1);
        System.out.println(thotelFacility+"这是数据，+++++++++++++++++++++++++");
        thotelFacilityService.insertSelective(thotelFacility);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("添加成功");
        return jsonData;
    }

    @RequestMapping(value = "/deletepiliang")
    @ResponseBody
    public JsonData deletepiliang(ThotelFacility thotelFacility) {
        System.out.println("thotelFacility"+thotelFacility);
        String[] ids= thotelFacility.getIds().split(",");
        System.out.println("ids"+ids);
        Integer[] aa = (Integer[]) ConvertUtils.convert(ids,Integer.class);
//        Integer[] a = (Integer[]) ids;
        thotelFacility.setBookIds(aa);
        thotelFacilityService.deletepiliang(thotelFacility);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("删除成功");
        return jsonData;
    }

    @RequestMapping(value = "/updateByPrimaryKeySelective")
    @ResponseBody
    public JsonData updateByPrimaryKeySelective(ThotelFacility thotelFacility) {
        thotelFacilityService.updateByPrimaryKeySelective(thotelFacility);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("修改成功");
        return jsonData;
    }



    @RequestMapping(value = "/deleteByPrimaryKey")
    @ResponseBody
    public JsonData deleteByPrimaryKey(ThotelFacility thotelFacility) {
        System.out.println("thotelFacility"+thotelFacility);
        thotelFacilityService.deleteByPrimaryKey(thotelFacility);
        JsonData jsonData = new JsonData();
        jsonData.setCode(0);
        jsonData.setMessage("删除成功");
        return jsonData;
    }
}
